package com.ykdl.member.kid.marketcard;

import java.util.ArrayList;
import java.util.List;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;

import android.app.SearchManager.OnCancelListener;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ykdl.member.constant.KidAction;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.MyPagerAdapter;
import com.ykdl.member.kid.beans.TicketBean;
import com.ykdl.member.kid.beans.TicketListBean;
import com.ykdl.member.kid.fragments.CouponFragment;
import com.ykdl.member.kid.fragments.CouponFragment_New;
import com.ykdl.member.kid.fragments.StoreFragment;
import com.ykdl.member.kid.gears.BaseFragmentActivity;
import com.ykdl.member.kid.gears.MyGoodLifeActivity;
import com.ykdl.member.kid.marketcard.MyCouponActivity.getDataTag;
import com.ykdl.member.kid.util.AccessTokenKeeper;
import com.ykdl.member.views.FocusTextView;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

/********************************************************************************
 * 
 ** 作者： jiafeiyu 创始时间：2015-4-27 描述： 门店货架
 *********************************************************************************/
public class StoreCouponActivity extends BaseFragmentActivity implements OnClickListener{

	private TextView mTVStore;
	private TextView mTVCoupon;
	private ViewPager mTVPager;
	private FocusTextView title;
	private int bmpW;
	private int currIndex = 0;
	private int offset = 0;
	private ImageView imageView;
	private List<Fragment> mFragList;
	private CouponFragment_New mCouponFragment;
	private StoreFragment mStoreFragment;
	private ArrayList<TicketBean> tickets;
	private String store_id;
	private String store_name="";
	private boolean isStore=true;
	private WebView webView ;
	private static AccessTokenKeeper mTokenKeeper;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		store_id = this.getIntent().getStringExtra(KidAction.STORE_ID);
		store_name = this.getIntent().getStringExtra(KidAction.STORE_NAME);
		isStore = this.getIntent().getBooleanExtra(KidAction.IS_STORE, true);
		setContentView(R.layout.activity_store_coupon);
		initViews();
	}

	private void initViews() {
//		InitImageView();
		webView =(WebView)findViewById(R.id.webView);
		/*findViewById(R.id.left).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		findViewById(R.id.right).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				//去门店详情
				Intent intent = new Intent(StoreCouponActivity.this,CardInfoActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.putExtra(KidAction.STORE_ID, store_id+"");
				intent.putExtra("from","true");
				startActivity(intent);
			}
		});*/
		mTokenKeeper = new AccessTokenKeeper(this);
		String url =KidConfig.PRODUCT_LIST_H5+store_id+"/product_list.html"+"?"+mTokenKeeper.getmAccessTokenTitle()+"="+mTokenKeeper.getmAccessToken();
		webView.loadUrl(url);
		/*title= (FocusTextView) findViewById(R.id.title);
		title.setText(store_name);
		mTVStore = (TextView) findViewById(R.id.tv_store_activity);
		mTVCoupon = (TextView) findViewById(R.id.tv_coupon_activity);
		mTVStore.setOnClickListener(this);
		mTVCoupon.setOnClickListener(this);
		mTVPager = (ViewPager) findViewById(R.id.viewpager);
		initFragment();
		mTVPager.setOnPageChangeListener(new OnPageChangeListener() {
			int one = bmpW+offset*2;

			@Override
			public void onPageSelected(int index) {
				Animation animation  = null;
				switch (index) {
				case 0:
					mTVStore.setTextColor(getResources().getColor(R.color.mycoupon_red));
					mTVCoupon.setTextColor(getResources().getColor(
							R.color.mycoupon_gray));
					animation = new TranslateAnimation(one, 0, 0, 0);
					break;
				case 1:
					mTVStore.setTextColor(getResources().getColor(
							R.color.mycoupon_gray));
					mTVCoupon
							.setTextColor(getResources().getColor(R.color.mycoupon_red));
					animation = new TranslateAnimation(offset, one, 0, 0);
					break;
				default:
					break;
				}
				
				currIndex = index;
//				Animation animation = new TranslateAnimation(one * currIndex,
//						one * index, 0, 0);
				animation.setFillAfter(true);
				animation.setDuration(300);
				imageView.startAnimation(animation);
				

			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});
		mTVPager.setOffscreenPageLimit(1);*/
		
	}
	/*public void setTitle(String store_name) {
		title.setText(store_name);
	}
	private void InitImageView() {
		imageView = (ImageView) findViewById(R.id.iv_maps_viewpager);
		bmpW = BitmapFactory.decodeResource(getResources(), R.drawable.mycoupon_red_line)
		.getWidth();
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		int screenW = dm.widthPixels;//
		LayoutParams params = (LayoutParams) imageView.getLayoutParams();
		params.width = screenW / 2;
		//imageView.setLayoutParams(params);
		offset = (screenW / 2 - bmpW) / 2;// 计算偏移量
		

		Matrix matrix = new Matrix();
		matrix.postTranslate(offset, 0);
		imageView.setImageMatrix(matrix);
	}

	private void initFragment() {
		mFragList = new ArrayList<Fragment>();
		mCouponFragment = new CouponFragment_New(store_id);
		mStoreFragment = new StoreFragment(store_id);
		mFragList.add(mStoreFragment);
		mFragList.add(mCouponFragment);
		MyPagerAdapter adapter = new MyPagerAdapter(
				getSupportFragmentManager(), mFragList);
		mTVPager.setAdapter(adapter);
		if (isStore) {
			mTVPager.setCurrentItem(0);
		}else {
			mTVPager.setCurrentItem(1);
			mTVStore.setTextColor(getResources().getColor(
					R.color.mycoupon_gray));
			int one = bmpW+offset*2;
			mTVCoupon
					.setTextColor(getResources().getColor(R.color.mycoupon_red));
			Animation animation = new TranslateAnimation(offset, one, 0, 0);
			animation.setFillAfter(true);
			animation.setDuration(300);
			imageView.startAnimation(animation);
		}
		
		mTVPager.setOffscreenPageLimit(2);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.tv_store_activity:
			mTVPager.setCurrentItem(0);
			break;
		case R.id.tv_coupon_activity:
			mTVPager.setCurrentItem(1);
			break;

		default:
			break;
		}
	}*/

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}



}
